#include <iostream>

using namespace std;

// problem 1
void swap(int& a, int& b) {
  a = a ^ b;
  b = a ^ b; // now b is orginal a
  a = a ^ b; // now a is orignal b
}

// problem 2

// problem 3
size_t fac_trailing_zero(size_t n) {
  size_t cnt = 0;
  for (size_t f = 5; f <= n; f *= 5) {
    cnt += (n / f);
  }
  return cnt;
}

// problem 4
int odd_max(int a, int b) {
  int c = a - b;
  int neg = (c >> 31) & 0x1;
  return a - neg * c;
}

// problem 5
pair<size_t, size_t> cal_hit(const char* soln, const char* guess) {
  int color_mask = 0;
  for (const char* p = soln; *p != '\0'; ++p)
    color_mask |= 1 << (int) (*p - 'A');

  size_t hit = 0;
  size_t pseudohit = 0; 
  for (const char* p = soln, *q = guess; *p != '\0'; ++p, ++q) {
    if (*p == *q)
      hit++;
    else if (color_mask & 1 << (int) (*q - 'A'))
      pseudohit++;
  }

  return make_pair(hit, pseudohit);
}

// problem 6 : n is in range [0, 999,999]
void read(ostream& os, size_t n) {
  
}

int main() {
  cout << "Problem 1:" << endl;
  int a = 1, b = 2;
  cout << "swap " << a << " and " << b << " : ";
  swap(a, b);
  cout << a << " and " << b << endl;
  cout << endl;

  cout << "Problem 3:" << endl;
  cout << "Number of trailing zeros for 10! is " << fac_trailing_zero(10) << " == 2" << endl;
  cout << "Number of trailing zeros for 26! is " << fac_trailing_zero(26) << " == 6" << endl;
  cout << endl;

  cout << "Problem 4: get max without comparision operator" << endl;
  cout << "Max of 10 and 15 is " << odd_max(10, 15) << endl;
  cout << endl;

  cout << "Problem 5:" << endl;
  pair<int, int> hits = cal_hit("RGGB", "YRGB");
  cout << "Hits and pseudo hits are " << hits.first << " and " << hits.second << endl;
  cout << endl;

  cout << "Problem 6:" << endl;
  cout << "Read number 1,112 : "; read(cout, 1112); cout << endl;
  cout << "Read number 0 : "; read(cout, 0); cout << endl;
  cout << "Read number 13,001 : "; read(cout, 13001); cout << endl;
  cout << endl;

  return 0;
}
